package com.hu.create;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;

/**
 * @author 00355760
 * @功能：
 * @版本： V1
 * @版权： 信息技术有限公司（http://www.mychery.com/）
 * @作者： 磐石战队开发组  00355760
 * @日期： 2024/9/19 10:50
 */
public class ThreadTest2 extends Thread {

    private String name;
    private String url;

    public ThreadTest2(String name, String url) {
        this.name = name;
        this.url = url;
    }

    @Override
    public void run() {
        DownLoader downLoader = new DownLoader();
        downLoader.download(url, name);
        System.out.println(Thread.currentThread().getName() + "下载了" + name);
    }

    public static void main(String[] args) {
        ThreadTest2 threadTest1 = new ThreadTest2("1.jpg","https://www.cnblogs.com/hellokuangshen/p/12531328.html");
        ThreadTest2 threadTest2 = new ThreadTest2("2.jpg","https://www.cnblogs.com/hellokuangshen/p/12531328.html");
        ThreadTest2 threadTest3 = new ThreadTest2("3.jpg","https://www.cnblogs.com/hellokuangshen/p/12531328.html");
        threadTest1.start();
        threadTest2.start();
        threadTest3.start();
    }
}

//下载器
class DownLoader{
    public void download(String url, String name){
        try {
            FileUtils.copyURLToFile(new URL(url), new File(name));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

